package com.humanmonth.home.component.page.htree
{
	import flash.events.Event;
	
	import mx.charts.events.ChartItemEvent;
	import mx.charts.series.items.PieSeriesItem;
	import mx.events.FlexEvent;
	import mx.charts.PieChart;
	public class DataBoardAs extends DataBorad
	{ 
		public function DataBoardAs()
		{
			super();
			this.addEventListener(FlexEvent.SHOW,bindPieData);
		}
		
		public function bindPieData(event:Event):void{
			this.myPieChart.dataProvider=this.toPieData();
			this.myPieSeries.labelFunction=displayGold;
			this.myPieChart.addEventListener(ChartItemEvent.ITEM_CLICK,setExplode);
		}
		
        private function displayGold(data:Object, field:String, index:Number, percentValue:Number):String {
            return data.order + "级部门:"+String(percentValue).substr(0,3)+"%\n总数: "+data.count;
        }
		/**
		 * 返回饼图需要的数组 
		 */
		public function toPieData():Array{
			var result:Array=new Array();
			var hasAdd:Boolean=false;
			for each (var nodeAs:NodeAs in NodeAs.allNode){
				for each (var obj:Object in result){
					if(obj.order==nodeAs.myOrder){
						obj.count+=1;
						hasAdd=true;
						break; 
					}
				}
				if(hasAdd){
					hasAdd=false;
				}else{
					result.push({order:nodeAs.myOrder,count:1});
				}
			}
			return result;
		}
		
		public function setExplode(event:ChartItemEvent):void{
			var item:PieSeriesItem = event.hitData.chartItem as PieSeriesItem;
			var arr:Array=[];
			arr[item.index]=0.1;
			this.myPieSeries.perWedgeExplodeRadius=arr;
		}
		
	}
}